package com.xnew.utils;

import com.alibaba.fastjson.JSONObject;
import com.xnew.bean.common.SysUserInfo;
import com.xnew.exception.CustomException;

import javax.servlet.http.HttpServletRequest;


/**
 * 获取当前登录用户
 */
public class UserUtil {

    public static SysUserInfo getUserInfo(HttpServletRequest request) throws RuntimeException {
        String token = request.getHeader("token");

        String userStr = RedisUtil.get(token);
        if(userStr==null || userStr.length()==0)
        {
            throw  new CustomException(500,"登录已经失效，请重新登录");
        }
        SysUserInfo user = JSONObject.parseObject(userStr, SysUserInfo.class);
        return user;
    }
}